function validateChangePasswordForm(){
	
	if(checkMandatoryFields() && checkLength() && matchPassword()){
		return true;
	}else{
		return false;
	}
	
}

function checkMandatoryFields(){
	
	var currentPassword = document.getElementById("currentPassword");
	var newPassword = document.getElementById("newPassword");
	var confirmNewPassword = document.getElementById("confirmNewPassword");
	
	if(currentPassword.value == null || (currentPassword.value != null && currentPassword.value.length == 0)){
		currentPassword.style.background = 'Yellow';
		alert("Current Password field has not been filled in.");
		return false;
	}else{
		currentPassword.style.background = 'White';
	}
	if(newPassword.value == null || (newPassword.value != null && newPassword.value.length == 0)){
		newPassword.style.background = 'Yellow';
		alert("New Password field has not been filled in.");
		return false;
	}else{
		newPassword.style.background = 'White';
	}
	if(confirmNewPassword.value == null || (confirmNewPassword.value != null && confirmNewPassword.value.length == 0)){
		confirmNewPassword.style.background = 'Yellow';
		alert("Confirm new Password field has not been filled in.");
		return false;
	}else{
		confirmNewPassword.style.background = 'White';
	}
	
	return true;
	
}

function checkLength(){
	
	var newPassword = document.getElementById("newPassword");
	var confirmNewPassword = document.getElementById("confirmNewPassword");
	
	if((newPassword.value != null) && (newPassword.value.length < 6)){
		alert("New Password can not be less than 6 characters.");
		return false;
	}
	if((confirmNewPassword.value != null) && (confirmNewPassword.value.length < 6)){
		alert("Confirm new Password can not be less than 6 characters.");
		return false;
	}
	
	return true;
	
}

function matchPassword(){
	
	var newPassword = document.getElementById("newPassword");
	var confirmNewPassword = document.getElementById("confirmNewPassword");
	
	if((newPassword.value != null) && (confirmNewPassword.value != null) && (newPassword.value!=confirmNewPassword.value)){
		alert("New Password does not match with Confirm New Password.");
		return false;
	}
	return true;
	
}

function handleCancel(){
	document.forms["changePasswordForm"].action="changePassword.html?method=handleCancel";
	document.forms.changePasswordForm.submit();
}
